//------------------------------------------
//	Excel workbook
//------------------------------------------
function OpenWks(strFileName,bVisible)
{
	var	pWks = null;
	var pApp = null;
	try
	{
		pApp = new ActiveXObject("Excel.Application");
	}
	catch (e)
	{
		alert(e);
		return pWks;
	}
	pApp.DisplayAlerts = false;
	pApp.visible = bVisible==false?false:true;
	var pWks = pApp.Workbooks.Open(strFileName);
	return pWks;
}

function CloseWks(pWks, bSave)
{
	if (pWks)
	{
		try
		{
			if (bSave)
			{
				pWks.Save();
			}
			pWks.Close();
			pWks.Appication.Quit();
		}
		catch (e)
		{
		}
		
	}
}

//------------------------------------------
//			Excel worksheet
//------------------------------------------
function GetAllSheetNameSet(pWks, bGetIndex)
{
	var	strNameSet = [];
	
	try
	{		
		var pSheet;
		for(var i=1;i<=pWks.Worksheets.Count;i++)
		{
			pSheet = pWks.Worksheets(i);

			var nCount = 0;
			if(bGetIndex)
			{
				//-获取实际终止行-
				var str = GetCellText(pSheet, 1, 6);
				var strSet = str.split(",");
				if(strSet.length==2)
					nCount = parseInt(strSet[1]);
			}
			else
			{
				nCount = GetColNo(pSheet,"ADDRESS");
				if(nCount<=0)
					nCount = GetColNo(pSheet,"地址");
			}
			strNameSet.push({	name:pSheet.name,
								row:pSheet.UsedRange.Rows.Count,
								addresscol:nCount
								});
		}
	}
	catch (e)
	{
		alert("error in GetAllSheetNameSet!");
	}

	return strNameSet;
}

function GetSheet(pWks, strSheetName)
{
	var	pSheet = null;
	
	try
	{
		pSheet = pWks.Worksheets(strSheetName);
	}
	catch (e)
	{

	}
	return pSheet;
}

function GetCell(pSheet, nRow, nCol)
{
	var	pCell = pSheet.Cells(nRow,nCol);
	return pCell;
}

function GetCellValue(pSheet, nRow, nCol)
{
	var	vValue;
	var  pCell = GetCell(pSheet, nRow, nCol);
	if (pCell)
	{
		vValue = pCell.Value;
	}
	return vValue;
}

function GetCellText(pSheet, nRow, nCol)
{
	var	strText = "";
	var pCell = GetCell(pSheet, nRow, nCol);
	if(pCell)
		strText = pCell.Text;

	return strText;	
}


function SetCellText(pSheet, nRow, nCol, strText)
{
	var pCell = GetCell(pSheet, nRow, nCol);
	if(pCell)
		pCell.Value = strText;
}

//-根据名称获取列号-
function GetColNo(pSheet, strColName)
{
	var	nCol = 0;
	for(var i=pSheet.UsedRange.Column; i<=pSheet.UsedRange.Column + pSheet.UsedRange.Columns.Count - 1; i++)
	{
		if(pSheet.Cells(1, i).Text == strColName)
		{
			nCol = i;
			break;
		}
	}
	return nCol;
}